// Copyright 2011 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
// Classes that builds specifications defined in
// datawarehouse/supersonic/structure/proto/structure.proto

#ifndef SUPERSONIC_CURSOR_CORE_SPECIFICATION_BUILDER_H_
#define SUPERSONIC_CURSOR_CORE_SPECIFICATION_BUILDER_H_

#include <string>
using std::string;

#include "supersonic/utils/scoped_ptr.h"

#include "supersonic/utils/macros.h"
#include "supersonic/proto/specification.pb.h"

namespace supersonic {

// Constructs ExtendedSortSpecification used by ExtendedSort (which is a
// Sort that supports case-insensitive sorting and limiting the number of rows
// returned).
class ExtendedSortSpecificationBuilder {
 public:
  ExtendedSortSpecificationBuilder() :
    specification_(new ExtendedSortSpecification()) {}

  ~ExtendedSortSpecificationBuilder() {}

  // Adds a key to the sort specification. If the attribute is not a string,
  // is_case_sensitive can be filled with any value.
  ExtendedSortSpecificationBuilder* Add(
      const string& attribute_name,
      const ColumnOrder& column_order,
      bool is_case_sensitive);

  // Adds a limit to the number of records returned.
  ExtendedSortSpecificationBuilder* SetLimit(size_t limit);

  // Returns the message generated by this builder. Can only be called once.
  ExtendedSortSpecification* Build();

 private:
  scoped_ptr<ExtendedSortSpecification> specification_;
};

}  // namespace supersonic

#endif  // SUPERSONIC_CURSOR_CORE_SPECIFICATION_BUILDER_H_
